/*
Copyright (C) 2009-2011 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#pragma once

#include "Mypool.h"

class MySQL {
private:
	static MySQL* instance;
	static SimpleConnectionPool *mypool;
	string host, username, password, database;
	short port;
public:
	MySQL(){
		instance = this;
	}
	static MySQL* getInstance(){
		if(instance == 0)
			return new MySQL();
		return instance;
	}
	void setHost(string h){
		host = h;
	}
	void setUsername(string user){
		username = user;
	}
	void setPassword(string pass){
		password = pass;
	}
	void setDatabase(string db){
		database = db;
	}
	void setPort(short p){
		port = p;
	}
	void connectToMySQL();
	int getInt(char* table, int id, char* value);
	void setInt(char* table, char* wht, int id, int value);
	void setString(char* table, char* wht, int id, char* value);
	bool isString(char* table, char* whr, string wht);
	string getString(char* table, char* whr, char* wht, char* value);
	string getString(char* table, char* whr, int wht, char* value);
	vector<int> getCharactersIds(int id, int maxchars);
	int showEquips(int id, int equips[30][2]);
	int getInt(char* table, char* whr, string wht, char* value);
	void createEquip(int equipid, int type, int charid);
	void getCharacter(int id, string info[32]);
	bool checkIpBan(string IP);
	void addIpBan(string IP);
	void unBan(string pname);
	void ban(string pname);
	SimpleConnectionPool *getPool(){
		return mypool;
	}
};
